import { defineStore } from 'pinia';
import { ref, reactive } from 'vue';
import { loginByUser } from '@/api/user';
interface UserInfo {
  username: string;
}
const useUserStore = defineStore(
  'userStore',
  () => {
    const token = ref(null);
    const refreshToken = ref(null);
    const userInfo: UserInfo = reactive({
      username: '',
    });
    async function loginByUserName(data: ModelType) {
      const r = await loginByUser(data);
    }
    function getToken() {
      return token.value;
    }
    function getRefreshToken() {
      return refreshToken.value;
    }
    function removeToken() {
      token.value = null;
      refreshToken.value = null;
    }
    return { token, loginByUserName, userInfo, getToken, getRefreshToken, removeToken };
  },
  {
    persist: true,
  },
);
export default useUserStore;
